home *** CD-ROM | disk | FTP | other *** search
- Rem Word Search
- Rem By Steven Ohmert
-
- CLS
-
- Rem Define constants
- Level = 1
- allowReverse = FALSE
-
- Rem How many words?
- totalWords = 30 ' number of words in Data statements
- wordsToFind = 5 ' number we try to find each game
-
- Rem Get level settings from user
- Gosub Setup
-
- Rem Set up difficulties per level
- if Level = 1 Then columns = 15
- if Level = 2 Then columns = 17
- if Level = 3 Then columns = 20
- if Level = 4 Then columns = 23
- if Level = 5 Then columns = 26
- rows = int(columns / 2)
- listColumn = columns + 3
- listRow = 0
-
- Dim Grid$(columns,rows)
- Dim GridColor(columns,rows)
- Dim WordList$(totalWords)
- Dim Words$(wordsToFind)
- Dim WordStart(wordsToFind)
- Dim WordStop(wordsToFind)
- Dim WordMethod(wordsToFind)
-
- StartGame:
- Rem Start off clean
- numberSolved = 0
-
- Rem Clear the grid
- for r = 1 to rows
- for c = 1 to columns
- Grid$(c,r) = ""
- GridColor(c,r) = 21
- next
- next
-
- Rem Get all of the words into an array
- for i = 1 to totalWords
- Read WordList$(i)
- Next i
-
- Rem Get the words for this game
- for i = 1 to wordsToFind
- gotWord = FALSE
- while gotWord = FALSE
- w = Random(1,totalWords)
- if WordList$(w) <> "" then gotWord = TRUE
- wend
- Rem add word to our list, then clear it
- Rem from list of available words
- Words$(i) = WordList$(w)
- WordList$(w) = ""
- next
-
- Rem For each word, find a place for it
- For currentWord = 1 to wordsToFind
-
- Fit = FALSE
- While Fit = FALSE
- Rem find an open starting spot
- letter$ = "*"
- while letter$ <> ""
- col = random(1,columns)
- row = random(1,rows)
- letter$ = grid$(col,row)
- wend
-
- method = Random(1,4)
- if method = 1 then Gosub HFitWord
- if method = 2 then Gosub VFitWord
- if method = 3 then Gosub DDFitWord
- if method = 4 then Gosub DUFitWord
-
- wordStart(currentWord) = row * columns + col
- wordMethod(currentWord) = method
- if method <> 2 Then col = col + wLen-1
- if method <> 1 AND method <> 4 Then row = row + wLen-1
- if method = 4 Then row = row - (wLen-1)
- wordStop(currentWord) = row * columns + col
-
- Wend
- Next
-
- REM Now, set the unused areas to random letters
- for row = 1 to rows
- for col = 1 to columns
- if Grid$(col,row) = "" Then
- Grid$(col,row) = chr$(random(65,90))
- 'Grid$(col,row) = "."
- Endif
- Next
- Next
-
-
- REM OKAY! We've made our grid! Print it out!
- CLS
- Gosub PrintGrid
-
- Rem Now print out the word list
- TextColor 66 'Feelin' Blue
- for i = 1 to wordsToFind
- position listColumn,i-1+listRow
- print Words$(i);
- next
-
- firstClickedCol = 0
- firstClickedRow = 0
-
- Rem get the user click, and see if we clicked on a word or not
- while numberSolved < wordsToFind
- clickedRow = 0
- clickedCol = 0
- while clickedRow = 0 OR clickedCol = 0
- Gosub GetGridClick
- wend
-
- Rem Undo any previous 'first click' that is left over
- If firstClickedCol > 0 and firstClickedRow > 0 then
- TextColor GridColor(firstClickedCol,firstClickedRow)
- Position firstClickedCol-1,firstClickedRow-1
- Print Grid$(firstClickedCol,firstClickedRow);
- Endif
- Rem Make the letter we click on Green
- TextColor 156 'Soylent Green
- Position clickedCol-1,clickedRow-1
- Print Grid$(clickedCol,clickedRow);
- Rem remember this so we can undo it later
- firstClickedCol = clickedCol
- firstClickedRow = clickedRow
-
- sq = clickedRow * columns + clickedCol
-
- Rem look for start of word in list
- foundWord = 0
- reverse = FALSE
- for i = 1 to wordsToFind
- if wordStart(i) = sq then
- foundWord = i
- Endif
- Next
-
- Rem look for end of word in list
- if foundWord = 0 Then
- for i = 1 to wordsToFind
- if wordStop(i) = sq then
- foundWord = i
- reverse = TRUE
- EndIf
- Next
- Endif
-
- if foundWord Then
- startCol = wordStart(foundWord) Mod columns
- startRow = Int(wordStart(foundWord) / columns)
- endCol = wordStop(foundWord) Mod columns
- endRow = Int(wordStop(foundWord) / columns)
- length = Len(Words$(foundWord))
- if wordMethod(foundWord) <> 2 Then endCol = clickedCol + length-1
- if wordMethod(foundWord) <> 1 AND wordMethod(foundWord) <> 4 Then endRow = clickedRow + length-1
- if wordMethod(foundWord) = 4 Then endRow = clickedRow - length +1
-
- clickedRow = 0
- clickedCol = 0
- while clickedRow = 0 OR clickedCol = 0
- Gosub GetGridClick
- wend
-
- firstClickedCol = clickedCol
- firstClickedRow = clickedRow
-
- Rem if we clicked on the end first, let's reverse our expectations
- if reverse then
- endRow = startRow
- endCol = startCol
- Endif
-
- if clickedRow = endRow AND clickedCol = endCol Then
- Sound "Whiz"
- Rem 'walk' along the word according to it's placement method
- Rem and redraw all the letters in red
- TextColor 94
- for i = 1 to length
- GridColor(startCol,startRow) = 94
- Position startCol-1,startRow-1
- Print Grid$(startCol,startRow);
- if wordMethod(foundWord) <> 2 then startCol = startCol + 1
- if wordMethod(foundWord) <> 1 AND wordMethod(foundWord) <> 4 then startRow = startRow + 1
- if wordMethod(foundWord) = 4 then startRow = startRow - 1
- next
- numberSolved = numberSolved + 1
-
- firstClickedCol = 0
- firstClickedRow = 0
-
- Rem cross off the word from the list
- x1 = listColumn * 8 + 4
- x2 = (listColumn + Len(words$(foundWord))) * 8 - 4
- y = (listRow+foundWord-1) * 16 + 8
- Color 157
- for i = 0 to 2
- Line x1,y+i to x2,y+i
- next
- Rem 'remove' word from word list so that we can't choose it
- Rem more than once!
-
- Endif
-
- Endif
- Wend
-
- TextColor 204
- Position 0,13
- Print "Congratulations! You got them all!";
- Sleep 35
- End
-
-
- REM See if we can fit a word horizontally
- HFitWord:
-
- Rem first, see if it will fit
- wLen = Len(Words$(currentWord))
- wLeft = columns - col
- if wLen <= wLeft Then
- w$ = Words$(currentWord)
- Fit = TRUE
- if allowReverse = TRUE And Random(1,100) > 50 Then
- Rem try to fit the word backwards
- for i = 0 to wLen-1
- IF Grid$(col+i,row) <> "" AND Grid$(col+i,row) <> Mid$(w$,wLen-i,1) THEN
- Goto TryForward
- EndIf
- Next
- Rem it fits: Record the word
- Fit = TRUE
- For i = 0 to wLen-1
- Grid$(col+i,row) = Mid$(w$,wLen-i,1)
- Next
- Return
- else
- TryForward:
- for i = 0 to wLen-1
- IF Grid$(col+i,row) <> "" AND Grid$(col+i,row) <> Mid$(w$,i+1,1) THEN
- Goto HFail
- EndIf
- Next
- Rem it fits: record the word
- Fit = TRUE
- for i = 0 to wLen-1
- Grid$(col+i,row) = Mid$(w$,i+1,1)
- Next
- Return
- EndIf
- Endif
-
- Rem Failed to fit word horizontally at this location
- HFail:
- Fit = FALSE
- Return
-
- REM See if we can fit a word vertically
- VFitWord:
- Rem first, see if it will fit
- wLen = Len(Words$(currentWord))
- wLeft = rows - row
- if wLen <= wLeft Then
- w$ = Words$(currentWord)
- Fit = TRUE
- if allowReverse = TRUE And Random(1,100) > 50 Then
- Rem try to fit the word backwards
- for i = 0 to wLen-1
- IF Grid$(col,row+i) <> "" AND Grid$(col,row+i) <> Mid$(w$,wLen-i,1) THEN
- Goto TryForward2
- EndIf
- Next
- Rem it fits: Record the word
- Fit = TRUE
- For i = 0 to wLen-1
- Grid$(col,row+i) = Mid$(w$,wLen-i,1)
- Next
- Return
- else
- TryForward2:
- for i = 0 to wLen-1
- IF Grid$(col,row+i) <> "" AND Grid$(col,row+i) <> Mid$(w$,i+1,1) THEN
- Goto VFail
- EndIf
- Next
- Rem it fits: record the word
- Fit = TRUE
- for i = 0 to wLen-1
- Grid$(col,row+i) = Mid$(w$,i+1,1)
- Next
- Return
- EndIf
- Endif
-
- Rem Failed to fit word vertically at this location
- VFail:
- Fit = FALSE
- Return
-
- REM See if we can fit a word diagonally, down
- DDFitWord:
- Rem first, see if it will fit
- wLen = Len(Words$(currentWord))
- wLeftH = columns - col
- wLeftV = rows - row
- wLeft = wLeftV
- if wLeftV > wLeftH Then wLeft = wLeftH
- if wLen <= wLeft Then
- w$ = Words$(currentWord)
- Fit = TRUE
- if allowReverse = TRUE And Random(1,100) > 50 Then
- Rem try to fit the word backwards
- for i = 0 to wLen-1
- IF Grid$(col+i,row+i) <> "" AND Grid$(col+i,row+i) <> Mid$(w$,wLen-i,1) THEN
- Goto TryForward3
- EndIf
- Next
- Rem it fits: Record the word
- Fit = TRUE
- For i = 0 to wLen-1
- Grid$(col+i,row+i) = Mid$(w$,wLen-i,1)
- Next
- Return
- else
- TryForward3:
- for i = 0 to wLen-1
- IF Grid$(col+i,row+i) <> "" AND Grid$(col+i,row+i) <> Mid$(w$,i+1,1) THEN
- Goto DDFail
- EndIf
- Next
- Rem it fits: record the word
- Fit = TRUE
- for i = 0 to wLen-1
- Grid$(col+i,row+i) = Mid$(w$,i+1,1)
- Next
- Return
- EndIf
- Endif
-
- Rem Failed to fit word diagonally at this location
- DDFail:
- Fit = FALSE
- Return
-
- REM See if we can fit a word diagonally, up
- DUFitWord:
- Rem first, see if it will fit
- wLen = Len(Words$(currentWord))
- wLeftH = columns - col
- wLeftV = row
- wLeft = wLeftV
- if wLeftV > wLeftH Then wLeft = wLeftH
- if wLen <= wLeft Then
- w$ = Words$(currentWord)
- Fit = TRUE
- if allowReverse = TRUE And Random(1,100) > 50 Then
- Rem try to fit the word backwards
- for i = 0 to wLen-1
- IF Grid$(col+i,row-i) <> "" AND Grid$(col+i,row-i) <> Mid$(w$,wLen-i,1) THEN
- Goto TryForward4
- EndIf
- Next
- Rem it fits: Record the word
- Fit = TRUE
- For i = 0 to wLen-1
- Grid$(col+i,row-i) = Mid$(w$,wLen-i,1)
- Next
- Return
- else
- TryForward4:
- for i = 0 to wLen-1
- IF Grid$(col+i,row-i) <> "" AND Grid$(col+i,row-i) <> Mid$(w$,i+1,1) THEN
- Goto DUFail
- EndIf
- Next
- Rem it fits: record the word
- Fit = TRUE
- for i = 0 to wLen-1
- Grid$(col+i,row-i) = Mid$(w$,i+1,1)
- Next
- Return
- EndIf
- Endif
-
- Rem Failed to fit word diagonally at this location
- DUFail:
- Fit = FALSE
- Return
-
- Rem Get the character clicked on by the user
- GetGridClick:
- clickedRow = 0
- clickedCol = 0
- for r = 0 to rows-1
- for c = 0 to columns-1
- if ClickRect(c*8,r*16 to c*8+7,r*16+15) Then
- clickedRow = r+1
- clickedCol = c+1
- return
- EndIf
- Next
- Next
- Return
-
- Rem Print out the grid
- PrintGrid:
- home
- For row = 1 to rows
- For col = 1 to columns
- TextColor GridColor(col,row)
- print Grid$(col,row);
- Next
- Print
- next
- Return
-
-
- REM Title and setup
- Setup:
- CLS
- TextColor 21
- Print " W"
- Print " O"
- Print "SEARCH"
- Print " D"
- Print
- Print "By Steven Ohmert"
- Print
- Level = 0
- Position 0,10
- Print "Choose Level of Difficulty (1-5) "
- while Level < 1 OR Level > 5
- Position 33,10
- Input Level
- Wend
- Print "Allow words to go backwards? (Y/N) "
- a$ = ""
- while a$ <> "N" AND a$ <> "Y"
- a$ = upper$(inkey$)
- wend
- if a$ = "Y" then allowReverse = TRUE
- Return
-
- Rem Data of words in the program
- Data BASIC,APPLE,PEACH,COMPUTER,TRICYCLE
- Data TORNADO,GARBAGE,SUNSHINE,PRETTY,MEDIA
- Data EXPERIMENT,TECHNIQUE,CHALLENGE,ACTIVE,SPEECH
- Data TRADITION,COFFEE,MEMORY,STANDING,ORANGE
- Data DRAMA,FOUNDATION,LISTEN,NATURAL,WATER
- Data SUPPORT,TYRANNY,DINOSAUR,COBRA,PUPPY
-
-
-
-